<template>
  <div class="content">
    <nut-navbar class="navbar" z-index="5" :clickable="false" fixed safe-area-inset-top>
      <template #content>
        <span>{{ t(String(route.meta.title)) }}</span>
      </template>
      <template #left>
        <img src="/imgs/club/arrow_left.png" alt="" @click="router.go(-1)" class="arrow_left" />
      </template>
      <template #right>
        <span class="save"></span>
      </template>
    </nut-navbar>

    <!-- tabs -->
    <nut-tabs @change="tabChange" v-model="value" title-scroll title-gutter="10" v-if="approvalTabList">
      <nut-tab-pane :title="t(item.name)" :pane-key="item.id" v-for="item in approvalTabList" :key="item.id">
        <!-- 搜索 -->
        <div class="search_box">
          <nut-searchbar class="search_input" placeholder="搜索成员ID或账号" v-model="searchVal"
            @change="onClickSearch" shape="square" background="transparent" input-background="#1D1C3C">
            <template #leftin>
              <iconpark-icon name="sousuo" style="margin-right: 14px;" size="14" />
            </template>
          </nut-searchbar>
          <span class="search_btn">搜索</span>
        </div>
        <!-- 成员 -->
        <div class="member_container">
          <div
            v-for="(member, index) in members"
            :key="member.id"
            class="member_item"
          >
            <div class="member_info">
              <img :src="member.avatar" alt="头像" class="member_avatar" />
              <div class="info">
                <div class="name_section">
                  <p class="member_name">{{ member.name }}</p>
                  <span
                    v-if="member.role"
                    class="tag"
                    :class="{
                      creator: member.role === 'creator',
                      admin: member.role === 'admin'
                    }"
                  >
                    <em class="tag_text">{{ member.role === 'creator' ? '创建者' : (member.role === 'admin' ? '管理员' : '')  }}</em>
                  </span>
                </div>
                <span class="vip_tag" :class="'vip_' + member.vipLevel">
                  <ImgT :src="member.vipLevel" alt="" />
                </span>
              </div>
            </div>
            <div class="member_actions">
              <span
                class="action_btn pass"
                @click="updateRole(index, 'pass')"
              >
                通过
              </span>
              <span
                class="action_btn reject"
                @click="updateRole(index, 'reject')"
              >
                拒绝
              </span>
              <span class="text passed">已通过</span>
            </div>
          </div>
        </div>
      </nut-tab-pane>
    </nut-tabs>

  </div>
</template>

<script setup lang="ts">
import { useI18n } from "vue-i18n";
import { ref, reactive, onMounted } from "vue";
import {useRoute, useRouter} from "vue-router";

const route = useRoute();
const router = useRouter();
const { t } = useI18n();

const value = ref(1)
const approvalTabList = reactive([
  {
    id: 1,
    name: "成员审核",
  },
  {
    id: 2,
    name: "管理员审核",
  },
]);
const seleteType: any = ref("成员审核");
const tabChange = (item: any) => {
  console.log('item', item)
    value.value = item.paneKey
    // Session.set('activityNum', item.paneKey)
    const obj: any = {
        1: '成员审核',
        2: '管理员审核',
    }
    seleteType.value = obj[item.title]
}

const searchVal = ref('')
const searchValFalg = ref(false)
const onClickSearch = () => {
  if (!searchVal.value) {

  }
  searchValFalg.value = true
}

// 成员列表
const members = reactive([
  {
    id: 1,
    name: "Frank002",
    avatar: "/imgs/club/member_avatar.png",
    vipLevel: "/imgs/club/vip.png",
    role: "creator",
  },
  {
    id: 2,
    name: "Frank002",
    avatar: "/imgs/club/member_avatar.png",
    vipLevel: "/imgs/club/vip.png",
    role: "admin",
  },
  {
    id: 3,
    name: "Frank002",
    avatar: "/imgs/club/member_avatar.png",
    vipLevel: "/imgs/club/vip.png",
    role: "normal",
  },
]);

// 审核
const updateRole = (index: number, role: "pass" | "reject") => {
  console.log('index or role', index, role)
  // if (members[index].role === "creator") return; // 创建者无法更改角色
  // members[index].role = role;
};

// 移除成员
// const removeMember = (index: number) => {
//   members.splice(index, 1);
// };

onMounted(async () => {
  seleteType.value = '成员审核'
  value.value = 1
});
</script>

<style scoped lang="scss">
.content {
  font-size: 14px;
  margin: 0 0 10px;

  .arrow_left {
    width: 24px;
    height: 24px;
  }

  .save {
    line-height: 32px;
    text-align: center;
    color: #5BD9FF;
  }

  .search_box {
    // width: 347px;
    margin: 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .search_input {
    
    :deep(.square) {
      border-radius: 8px;
      height: 44px;
      box-shadow: 0.5px 0.5px 1px 0px #2E296B inset;
    }
  }

  .search_btn {
    width: 82px;
    height: 44px;
    margin-right: 14px;
    font-size: 14px;
    line-height: 44px;
    text-align: center;
    color: #FFFFFF;
    background: linear-gradient(180deg, #5567FF 0%, #9E1EFF 100%);
    box-shadow: 0.5px 0.5px 1px 0px #9B9EFF inset;
    border-radius: 8px;
  }

  .member_container {
    // padding: 20px;
    width: 347px;
    margin: 0 auto;

    .member_item {
      height: 62px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      background-color: #131232;
      box-shadow: 0.5px 0.5px 1px 0px #2E296B inset;
      border-radius: 10px;
      padding: 10px 15px;
      margin-bottom: 10px;
      position: relative;

      .member_info {
        display: flex;
        align-items: center;
        

        .member_avatar {
          width: 50px;
          height: 50px;
          border-radius: 50%;
          margin-right: 10px;
        }

        .info {
          display: flex;
          flex-direction: column;

          .name_section {
            display: flex;
            align-items: center;
            gap: 8px;
            

            .member_name {
              font-size: 14px;
              font-weight: bold;
              margin: 0;
              color: #FFFFFF;
            }
            .tag {
              width: 45px;
              height: 36px;
              line-height: 32px;
              font-size: 10px;
              border-radius: 6px;
              color: #fff;
              position: absolute;
              left: 0;
              top: 0;
              z-index: 99;

               .tag_text {
                display: inline-block;
                transform: rotate(-40deg);
               }
            }

            .tag.creator {
              background: url(/imgs/club/cjz.png) no-repeat;
              background-size: 100% 100%;
            }

            .tag.admin {
              background: url(/imgs/club/gly.png) no-repeat;
              background-size: 100% 100%;
            }
          }

          .vip_tag {
            margin-top: 5px;

            img {
              width: 50px;
              height: 20px;
            }
          }
        }
      }

      .member_actions {
        display: flex;
        gap: 10px;

        .action_btn {
          height: 32px;
          line-height: 32px;
          font-size: 12px;
          text-align: center;
          color: #C6C4F5;
          padding: 0 8px;
          background: #282747;
          box-shadow: 0.5px 0.5px 1px 0px #C6C4F5 inset;
          border-radius: 8px;
        }

        .pass {
          background-color: #1DBA8B;
          color: #ffffff;
        }

        .reject {
          background-color: #282747;
          color: #C6C4F5;
        }
        .text {
          height: 32px;
          line-height: 32px;
          font-size: 12px;
        }
        
        .passed {
          color: #1DBA8B;
        }
        .rejected {
          color: #C6C4F5;
        }
      }
    }
  }


}
</style>
